import dayjs from 'dayjs';

export default class calculateTimeRemaining {
    static diff(endTime: string, startTime: string) {
        const end = dayjs(endTime);
        const start = dayjs(startTime);

        if (end.isBefore(start)) {
            return {
                hours: 0,
                minutes: 0,
                seconds: 0,
                milliseconds: 0,
                totalMilliseconds: 0
            };
        };

        const totalMilliseconds = end.diff(start);
        const duration = dayjs.duration(totalMilliseconds);

        return {
            hours: duration.hours(),
            minutes: duration.minutes(),
            seconds: duration.seconds(),
            milliseconds: duration.milliseconds(),
            totalMilliseconds: totalMilliseconds
        };
    };
};